package com.pioneer.app.sms.mobile;

import java.io.File;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.gotop.sms.fysms.Bacterin;
import com.gotop.sms.fysms.BacterinDAO;
import com.gotop.sms.fysms.UserBacterin;
import com.gotop.sms.fysms.UserBacterinDAO;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.pioneer.app.dev.osuser.user.Userlist;
import com.pioneer.app.dev.osuser.user.UserlistDAO;
import com.pioneer.app.sms.timeTask.MessageMg;
import com.pioneer.app.sms.timeTask.SMSTask;

public class SendMessAction extends ActionSupport implements Action, ServletRequestAware,ServletResponseAware {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(SendMessAction.class);

	private HttpServletResponse response;
	private HttpServletRequest request;
	private String toPersons;
	private Integer id;
	private String toMobiles;
	private String userName;
	private String title;
	private String content;
	private String mobile;
	private File mobilefile;
	
	private Date smstime;
	
	/**
	 * @desc:
	 * @param args :
	 * @auther : chen
	 * @date : Nov 26, 2008
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	public String doEXCELSMSInfor(){
		
		SendService service=new SendService();
		service.setContent(this.content);
		service.setTitle(this.title);
		service.setEXCELSMSFile(this.mobilefile);
		service.setSMS();
		
		return "sucess";
	}

	public String fysmsPage(){
		if(null!=this.id){
			UserBacterinDAO ubdao=new UserBacterinDAO();
			UserBacterin ubvo=ubdao.findById(this.id);
			Integer userId=ubvo.getUserId();
			UserlistDAO userDao=new UserlistDAO();
			Userlist user=userDao.findById(userId);
			this.mobile=user.getTelphone();
			this.toMobiles=user.getTelphone();
			this.userName=user.getCname();
			Integer bid=ubvo.getBacterinId();
			BacterinDAO bdao=new BacterinDAO();
			Bacterin bvo=bdao.findById(bid);
			this.title=bvo.getName();
			this.content=user.getCname()+"将在"+ubvo.getOrderTimeS()+"接种"+bvo.getName()+"请注意时间！";
		}
		
		
		return "sucess";
	}
	public String doUploadSMSInfor(){
		
		try{
			
//			System.out.println("content="+content);
//			System.out.println("title="+title);
//			System.out.println("file="+this.mobilefile.getName());
			SendService sendService=new SendService();
			sendService.setContent(content);
			sendService.setTitle(title);
			sendService.setMobile(this.toMobiles);
			sendService.setMobile(this.toPersons);
			//sendService.setUsers(this.toPersons);
			sendService.setMobileFile(this.mobilefile);
			if(null==this.smstime){
				sendService.setSMS();
			}else{
				SMSTask task=new SMSTask();
				task.setSendService(sendService);
				task.setSendDate(this.smstime);
				MessageMg.getInst().addTmpTask(task);
			}
		}catch(Exception e){
			logger.error("doUploadSMSInfor() 短信发送失败！", e);
			e.printStackTrace();
		}
		return "sucess";
	}
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
		if(null==toPersons)this.toPersons=request.getParameter("toPersons");
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response=response;
		
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public File getMobilefile() {
		return mobilefile;
	}

	public void setMobilefile(File mobilefile) {
		this.mobilefile = mobilefile;
	}

	public String getToPersons() {
		return toPersons;
	}

	public void setToPersons(String toPersons) {
		this.toPersons = toPersons;
	}

	public String getToMobiles() {
		return toMobiles;
	}

	public void setToMobiles(String toMobiles) {
		this.toMobiles = toMobiles;
	}

	public Date getSmstime() {
		return smstime;
	}

	public void setSmstime(Date smstime) {
		this.smstime = smstime;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

}
